"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let webSocketTool = {
    ws: null,
    listenMap: new Map(),
    start: function (wss) {
        let that = this;
        wss.on('connection', (ws) => {
            that.ws = ws;
            console.log('WinUI 管理面板连接成功！');
            ws.on('message', function (msg) {
                that.listenMap.forEach(function (func) {
                    if (typeof func === 'function') {
                        msg = JSON.parse(msg.toString());
                        func(msg);
                    }
                });
            });
        });
    },
    addListen: function (mark, func) {
        this.listenMap.set(mark, func);
    },
    send: function (msg) {
        if (this.ws) {
            this.ws.send(msg, (err) => {
                if (err)
                    console.log(`服务器错误: ${err}`);
            });
        }
    }
};
exports.default = webSocketTool;
